
EventDispatcher.prototype.__fireWidgetEvent = EventDispatcher.prototype.fireWidgetEvent;

/**
 * @function fireWidgetEvent
 * @param source string id of the widget that fires the event
 * @param eventType String The type of the event to be sent
 * @param eventData * Anything that needs to be transmitted (String, Object, ...)
 * @param target String Widget instance that will receive the event in case of unicast. Can be omitted or set to null for broadcast. Set to "REMOTE" for groupcast
 */

EventDispatcher.prototype.fireWidgetEvent = function(source, eventType, eventData, target) {
    if(target === "REMOTE"){
        //Fire groupcast Event
        GroupEvent.fireEvent(eventType, jQuery.toJSON(eventData), source);
    }else // Call standart function
        this.__fireWidgetEvent(source, eventType, eventData, target);
}
/**
 *@description handleFiring function with 1 more parameter : the user firing the event (sourceUser). See handleFiring function
 */
EventDispatcher.prototype.handleRemoteFiring = function(eventsForTarget, source, eventType, eventData, sourceUser)
{
	wantReceive = false;
	handler = null;

	if (eventsForTarget && eventsForTarget.acceptAll == true)
	{

		wantReceive = true;
		handler = eventsForTarget.eventHandler;
	}
	else
	{
		// We have to look up if it accepts to listen this source.
		sources = eventsForTarget.acceptedSources;
		for (i = 0; i < sources.length; i++)
		{
			if (sources[i]['eventSrc'] == source)
			{
				wantReceive = true;
				handler = sources[i]['eventHandler'];
				break;
			}
		}
	}

	if (wantReceive && handler)
	{
		handler({eventType: eventType, eventData: eventData, sourceUser: sourceUser});
	}
}
/**
 *@description showHide function without server notification. See showHide
 */
WidgetContainer.prototype.__showHide = function(){
    // this.id refers to the id of the min button
		var widgetId = this.id;
		var widgetMinButton = $('#min_' + this.id).get(0);

		/* update user interface */
		widgetMinButton.className = (widgetMinButton.className == 'widget_min_button') ? 'widget_max_button' : 'widget_min_button';
		widgetMinButton.title = (this.className == 'widget_min_button') ? I18n.__("Collapse") : I18n.__("Expand");

		$('#iframeContainer_'+widgetId).toggle();

		if (this.manifest['widget_type'] == 'local')
		{

			var iFrame 		= $('#iframeContainer_' + widgetId).find('.iframe').get(0);
			var innerDoc 	= iFrame.contentWindow || iFrame.contentDocument;

			if (innerDoc.onResize)
				innerDoc.onResize((widgetMinButton.className == 'widget_min_button') ? 'maximize' : 'minimize');
		}

		/* Notify the event */
		var eventType = (widgetMinButton.className == 'widget_min_button') ? EventDispatcher.EVENT_WIDGET_MAXIMIZED : EventDispatcher.EVENT_WIDGET_MINIMIZED;

		eventDispatcher.fireWidgetEvent(EventDispatcher.EVENT_SOURCE_PORTAL,
										eventType,
										{widgetId: widgetId},
										null);

}